package main

import (
	"context"
	"fmt"
	"github.com/Exayn/go-listmonk"
	"listmonkDemo/openai"
	"listmonkDemo/openai/CommonInterface"
)

func main() {

	//testServices()
	//return
	//useSdkGet()
	//campaigns()
	//campaignsCreate()
	//campaignsSend()

	//testOpenai()
	//openai.JsonDecode()

	var ClientInstance = openai.NewClientInstance()

	var AnalysisIns CommonInterface.Analysis
	AnalysisIns = &openai.AnalysisIndustry{
		Client: ClientInstance,
	}
	AnalysisIns.SetMessage(context.Background())
	AnalysisIns.GetResp(context.Background(), "learn")
}

func useSdkGet() {
	username := "listmonk"
	password := "listmonk"
	client := listmonk.NewClient("http://127.0.0.1:9000", &username, &password)
	service := client.NewGetSubscribersService()
	listIds := []uint{1, 2, 3}
	do, err := service.ListIds(listIds).Do(context.Background())
	if err != nil {
		return
	}
	//zaza := client.NewPostTransactionalService()
	//lala.ListIds()
	fmt.Println(do)

	//写一个正常的rest http请求
}

func campaigns() {
	username := "listmonk"
	password := "listmonk"
	url := "https://listmonk.ambitiousmeadow-9aaf9fa5.japaneast.azurecontainerapps.io"
	client := listmonk.NewClient(url, &username, &password)
	service := client.NewGetCampaignsService()
	do, err := service.Do(context.Background())
	if err != nil {
		return
	}
	fmt.Println(do)
}

func campaignsCreate() {
	username := "listmonk"
	password := "listmonk"
	url := "https://listmonk.ambitiousmeadow-9aaf9fa5.japaneast.azurecontainerapps.io"
	client := listmonk.NewClient(url, &username, &password)
	service := client.NewCreateCampaignService()

	//参数
	body := "<h3>Hi {{ .Subscriber.FirstName }}!</h3>\\n\\t\\t<p>This is a examples e-mail campaign. Your second name is {{ .Subscriber.LastName }} and you are from {{ .Subscriber.Attribs.city }}.</p>\\n\\t\\t<p>Here is a <a href=\\\"https://listmonk.app@TrackLink\\\">tracked link</a>.</p>\\n\\t\\t<p>Use the link icon in the editor toolbar or when writing raw HTML or Markdown,\\n\\t\\t\\tsimply suffix @TrackLink to the end of a URL to turn it into a tracking link. Example:</p>\\n\\t\\t<pre>&lt;a href=&quot;https:/&zwnj;/listmonk.app&#064;TrackLink&quot;&gt;&lt;/a&gt;</pre>\\n\\t\\t<p>For help, refer to the <a href=\\\"https://listmonk.app/docs\\\">documentation</a>.</p>\\n\\t\\t"
	templateId := uint(1)
	fromEmail := "abc <lzq900623@163.com>"
	subject := "zhuti Test pusher progress 001"
	typess := "regular"
	content_type := "richtext"
	name := "Test pusher progress 001"

	do, err := service.Body(body).TemplateId(templateId).FromEmail(fromEmail).
		Subject(subject).Type(typess).ContentType(content_type).Lists([]uint{1}).
		Messenger("email").Name(name).Tags([]string{"examples-campaign"}).Do(context.Background())
	if err != nil {
		return
	}
	fmt.Println(do)
}

func campaignsSend() {
	username := "listmonk"
	password := "listmonk"
	url := "https://listmonk.ambitiousmeadow-9aaf9fa5.japaneast.azurecontainerapps.io"
	client := listmonk.NewClient(url, &username, &password)
	service := client.NewUpdateCampaignStatusService()
	do, err := service.Id(9).Status("running").Do(context.Background())

	if err != nil {
		return
	}
	fmt.Println(do)
}
